GenerateGauss <- function(mx, my, dx, dy, n) {
  number = 0
  means = c(mx, my)
  cov = matrix(c(dx, 0, 0, dy), 2, 2)
  result = matrix()
  
  while (number < n) {
    points = rmnorm(n, means, cov)
    index = (points[,1]>0&points[,1]<1&points[,2]>0&points[,2]<1)
    if (number == 0) {
      result = matrix(points[index],ncol=2);
      number = number + nrow(result)
    }
    if (number != 0) {
      number = number + nrow(result)
      result = rbind(result,matrix(points[index],ncol=2))
    }
  }
  result = result[1:n, ]
  plot(result)
  return(result)
}

RandomGauss <- function(m1x, m1y, d1x, d1y, m2x, m2y, d2x, d2y, n1, n2) {
  result1<-GenerateGauss(m1x, m1y, d1x, d1y, n1);
  result2<-GenerateGauss(m2x, m2y, d2x, d2y, n2);

  class_number = matrix(c(1:n1*0+1, (n1+1):(n1+n2)*0-1),nrow = n1 + n2, ncol = 1)
  points=rbind(result1,result2)
  #plot(result1)
  result=cbind(points, class_number)
  #plot(points)
  write(t(result), "train3.txt", ncolumn = 3)
}

RandomGauss(0.75, 0.75, 0.2, 0.2, 0.25, 0.25, 0.2, 0.2, 300, 300)

#RandomGauss(0.9,0.7,0.003,0.003,0.1,0.2,0.003,0.003,100,100)

